package com.rover022.flixelgame.ui.equipupgrade
{
	import com.greensock.loading.ImageLoader;
	import com.rover022.flixelgame.GameConfig;
	import com.rover022.flixelgame.ui.BaseUI;
	import com.rover022.flixelgame.utils.ObjectFactory;
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.net.URLRequest;

	/**
	 * 通用型的格子ui 根据格子的不同显示不同样式的格子
	 * 英雄头像是他的子类
	 * 道具头像是他的子类
	 * @author flashpig
	 *
	 */
	public class GeneralityGridUI extends BaseUI
	{
		public static var heroImages:Array = ["assets/UI/alpha/HVGA/hero_icon_frame_1.pvr.png", "assets/UI/alpha/HVGA/hero_icon_frame_2.pvr.png", "assets/UI/alpha/HVGA/hero_icon_frame_3.pvr.png", "assets/UI/alpha/HVGA/hero_icon_frame_4.pvr.png", "assets/UI/alpha/HVGA/hero_icon_frame_5.pvr.png", "assets/UI/alpha/HVGA/hero_icon_frame_6.pvr.png", "assets/UI/alpha/HVGA/hero_icon_frame_7.pvr.png", "assets/UI/alpha/HVGA/hero_icon_frame_8.pvr.png", "assets/UI/alpha/HVGA/hero_icon_frame_9.pvr.png", "assets/UI/alpha/HVGA/hero_icon_frame_10.pvr.png", "assets/UI/alpha/HVGA/hero_icon_frame_11.pvr.png", "assets/UI/alpha/HVGA/hero_icon_frame_12.pvr.png"];
		public static var itemImages:Array = ["assets/UI/alpha/HVGA/equip_frame_white.pvr.png", "assets/UI/alpha/HVGA/equip_frame_green.pvr.png", "assets/UI/alpha/HVGA/equip_frame_blue.pvr.png", "assets/UI/alpha/HVGA/equip_frame_purple.pvr.png", "assets/UI/alpha/HVGA/equip_frame_orange.pvr.png"];
		public static var HEROTYPE:String = "herotype";
		public static var ITEMTYPE:String = "itemtype";
		/**
		 * 品质从0开始
		 */
		public var quality:uint = 0;
		public var maxQuality:uint = 5;
		/**
		 * 使用类型
		 */
		public var type:String = HEROTYPE;
		public var gridUrl:String;
		private var frontGroundSprite:Sprite;
		private var frameSprite:Sprite;
		private var imageSprite:Sprite;
		public var parentRef:*;
		public var gridWidth:Number = 86;
		public var gridHeight:Number = 86; //106
		public var picWidth:Number = 78;
		public var picHeight:Number = 78; //104

		public function GeneralityGridUI(_type:String)
		{
			type = _type;
			imageSprite = ObjectFactory.makeEContainer(this);
			frameSprite = ObjectFactory.makeEContainer(this);
			frontGroundSprite = ObjectFactory.makeEContainer(this);
			this.graphics.beginFill(0x0, 0.5);
			this.graphics.drawRect(0, 0, 50, 50);
			this.graphics.endFill();
		}

		public function centerImage():void
		{
			var num:int = (gridWidth - picWidth) / 2;
			imageSprite.x = num;
			imageSprite.y = num;
		}

		override public function dispose():void
		{
			parentRef = null;
			super.dispose();
		}

		/**
		 * 设置图片品质
		 * @param num
		 *
		 */
		public function setQuality(num:Number):void
		{
			quality = num;
			setFrameImage(qualityImages[num]);
		}

		public function get qualityImages():Array
		{
			if (type == HEROTYPE)
			{
				return heroImages;
			}
			else if (type == ITEMTYPE)
			{
				return itemImages;
			}
			return null;
		}

		/**
		 * 设置框图片
		 * @param num
		 *
		 */
		public function setFrameImage(url:String):void
		{
			frameSprite.removeChildren();
			trace(gridWidth, picWidth)
			new ImageLoader(GameConfig.webroot + url, {width: gridWidth, height: gridHeight, container: frameSprite}).load();
		}

		/**
		 * 设置pic图片
		 * @param num
		 *
		 */
		public function setImage(url:String):void
		{
			imageSprite.removeChildren();
			new ImageLoader(GameConfig.webroot + url, {width: picWidth, height: picHeight, container: imageSprite}).load();
		}

		/**
		 * 设置数据装载
		 */
		public function setDate(data:*):void
		{
			parentRef = data;
			setQuality(parentRef["quality"]);
			setImage(parentRef["imageUrl"]);
		}
	}
}
